<script setup lang="ts">
// 这里主要处理全局共享信息使用

import { computed, onMounted, ref } from 'vue';
import { setupDynamicRouter } from './router/routes';
import { useRoute, useRouter } from 'vue-router';
import ZhCn from 'element-plus/lib/locale/lang/zh-cn'
import { useSystemInfo } from './store';
// import ZhCn from "element-plus/dist/locale/zh-cn.mjs";
// import { ElConfigProvider } from 'element-plus';
const env = import.meta.env
// 初始化路由也应该在此处,目前存在于router 的beforEach中
const RouterInited = ref(false)
const router = useRouter()
const route = useRoute()
const systemInfo=useSystemInfo()
onMounted(() => {
  if (sessionStorage.getItem(env.VITE_TOKEN_KEY)) {
    // 已登陆,单刷新了页面
    if (env.DEV) console.log(Date.now(), "已经登录账户,且刷新了页面");
    const activeApp = sessionStorage.getItem("activeApp");
    setupDynamicRouter(activeApp || "system", router)
      .then((data) => {
        RouterInited.value = true
        router.push(route)
        systemInfo?.updateMenuList(data.originalMenuList)
      })
  } else {
    RouterInited.value = true
  }
})
const SystemInitComplete = computed(() => RouterInited.value)
</script>
<template>
  <ElConfigProvider size="default" :locale="ZhCn">
    <router-view v-if="SystemInitComplete" />
    <div id="app" v-else v-loading="!SystemInitComplete" element-loading-text="正在为您准备菜单"></div>
  </ElConfigProvider>
</template>

